package com.evenmo.hrms.mapper.oldmapper.dynaSqlProvider;

import com.evenmo.hrms.pojo.Dept;
import org.apache.ibatis.jdbc.SQL;

import java.util.Map;

public class DeptDynaSqlProvider {

    public String selectByParam(Map<String, Object> params) {
        return new SQL() {
            {

                SELECT("*");
                FROM("dept");
                Object obj = params.get("dept");
                if (obj != null) {
                    Dept dept = (Dept) obj;
                    if (dept.getId() != null) {
                        WHERE("id=#{dept.id}");
                    }
                    if (dept.getName() != null) {
                        WHERE("name=#{dept.name}");
//                        OR();
//                        WHERE("name like concat('%',#{dept.name},'%')");
                    }


                }
                Object like = params.get("likeParams");
                if (like != null) {
                    String likeParam = (String) like;
                    System.out.println("查询参数："+like);

                    if (likeParam != null) {
                        System.out.println("查询参数："+likeParam);
                        WHERE("name like concat('%',#{likeParams},'%')");
                    }

                }


            }
        }.toString();
    }

    public String updateByParams(Dept dept){
        return new SQL(){
            {

                UPDATE("dept");
                if (dept.getName()!=null){
                    SET("name=#{name}");
                }
                if (dept.getRemark()!=null){
                    SET("remark=#{remark}");
                }

                WHERE("id=#{id}");





            }
        }.toString();
    }
}
